;(function($){
	$.jgrid.extend({
		/**
		 * TODO:对jqGrid原生setRowData的重写
		 */
		setRowData : function(rowid, data, cssp) {
			var nm, success=true, title;
			this.each(function(){
				if(!this.grid) {return false;}
				var t = this, vl, ind, cp = typeof cssp, lcdata={};
				ind = t.rows.namedItem(rowid);
				if(!ind) { return false; }
				if( data ) {
					try {
						$(this.p.colModel).each(function(i){
							nm = this.name;
							if( data[nm] !== undefined) {
								lcdata[nm] = this.formatter && typeof(this.formatter) === 'string' && this.formatter == 'date' ? $.unformat.date.call(t,data[nm],this) : data[nm];
								vl = t.formatter( rowid, data[nm], i, data, 'edit');
								title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
								if(t.p.treeGrid===true && nm == t.p.ExpandColumn) {
									$("td:eq("+i+") > span:first",ind).html(vl).attr(title);
								} else {
									$("td:eq("+i+")",ind).html(vl).attr(title);
								}
							}
						});
						if(t.p.datatype == 'local') {
							var id = $.jgrid.stripPref(t.p.idPrefix, rowid),
							pos = t.p._index[id];
							if(t.p.treeGrid) {
								for(var key in t.p.treeReader ){
									if(lcdata.hasOwnProperty(t.p.treeReader[key])) {
										delete lcdata[t.p.treeReader[key]];
									}
								}
							}
							if(typeof(pos) != 'undefined') {
								t.p.data[pos] = $.extend(true, t.p.data[pos], lcdata);
							}
							lcdata = null;
						}
					} catch (e) {
						success = false;
					}
				}
				if(success) {
					if(cp === 'string') {$(ind).addClass(cssp);} else if(cp === 'object') {$(ind).css(cssp);}
					$(t).triggerHandler("jqGridAfterGridComplete");
					/**
					 * TODO:begin 同时修改grid的实际数据存储
					 */
					$(t).jqGrid("setGridDatasStoreById", rowid,data);
					/**
					 * TODO:end
					 */
				}
			});
			return success;
		}
	});
})(jQuery);
